package controllers;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;

import play.data.validation.Valid;
import models.Article;
import models.BaseModule;

/**
 * Form::Form主控制器,所有的Form都可以写在这里,方便管理
 * 
 * @see BaseModule
 * @since 1.0
 * @author Mr.J.
 * **/
public class Form extends Application implements BaseModule{
	public static void addArticle(@Valid Article article) throws NumberFormatException, FileNotFoundException, IOException{
		if(validation.hasErrors()){
			params.flash();
			validation.keep();
			ArticleAdmin.index();
		}
		Article art = new Article(article.title, article.introduce, article.content, getCurrutUser());
		art.save();
		ArticleAdmin.index(null,null,null);
	}
	
	public static void editArticle(@Valid Article article){
		if(validation.hasErrors()){
			params.flash();
			validation.keep();
			ArticleAdmin.edit(String.valueOf(article.id));
		}
		article.save();
		ArticleAdmin.edit(String.valueOf(article.id));
	}
}
